
class SbBool3
{
private:
  int state_; // 1: true, 0 : undef, -1 : false

  inline static int toState(bool b) { return b ? 1 : -1; }

  inline static int not(int a)        { return -a; }
  inline static int  eq(int a, int b) { return  a * b; }
  inline static int neq(int a, int b) { return -(a * b); }
  inline static int and(int a, int b) { return  (a < b) ? a : b; }
  inline static int  or(int a, int b) { return  (a > b) ? a : b; }

  inline SbBool3(int state) : state_(state) { }

public:
  inline static SbBool3 True()  { return  1; }
  inline static SbBool3 Undef() { return  0; }
  inline static SbBool3 False() { return -1; }

  inline bool isTrue()  const   { return  1 == state_; }
  inline bool isUndef() const   { return  0 == state_; }
  inline bool isFalse() const   { return -1 == state_; }

  inline SbBool3() : state_(0) { }
  inline SbBool3(bool b) : state_(toState(b)) { }
  inline SbBool3(SbBool3 const& other) : state_(other.state_) { }

  inline void operator = (bool b) { state_ = toState(b); }
  inline void operator = (SbBool3 other) { state_ = other.state_; }

  inline SbBool3  eq(bool b)         const { return eq(toState(b), state_); }
  inline SbBool3  eq(SbBool3 other)  const { return eq(other.state_, state_); }

  inline SbBool3 not()               const { return not(state_); }
  inline SbBool3 neq(bool b)         const { return neq(toState(b), state_); }
  inline SbBool3 neq(SbBool3 other)  const { return neq(other.state_, state_); }

  inline SbBool3 and(bool b)         const { return and(toState(b), state_); }
  inline SbBool3 and(SbBool3 other)  const { return and(other.state_, state_); }

  inline SbBool3  or(bool b)         const { return  or(toState(b), state_); }
  inline SbBool3  or(SbBool3 other)  const { return  or(other.state_, state_); }
};

